﻿using System;
using NUnit.Framework;
using Xenta.Events;
using Xenta.Operations;
using Xenta.Tests.Operations;

namespace Xenta.Tests.Events
{
    [TestFixture]
    public class OperationEventTests : OperationTest
    {
        [Test]
        public void PrePostExecute_Event_AreRaising()
        {
            bool preRaisedInt = false;
            bool postRaisedInt = false;
            bool preRaisedString = false;
            bool postRaisedString = false;

            Infrastructure.EventBroker.Subscribe<PreExecuteOperation>(x => preRaisedInt = true, typeof(CustomOperation<Int32>));
            Infrastructure.EventBroker.Subscribe<PostExecuteOperation>(x => postRaisedInt = true, typeof(CustomOperation<Int32>));
            Infrastructure.EventBroker.Subscribe<PreExecuteOperation>(x => preRaisedString = true, typeof(CustomOperation<String>));
            Infrastructure.EventBroker.Subscribe<PostExecuteOperation>(x => postRaisedString = true, typeof(CustomOperation<String>));

            Processor.Execute(new CustomOperation<Int32>(x => 1));

            preRaisedInt.IsTrue();
            postRaisedInt.IsTrue();
            preRaisedString.IsFalse();
            postRaisedString.IsFalse();

            Processor.Execute(new CustomOperation<String>(x => String.Empty));

            preRaisedString.IsTrue();
            postRaisedString.IsTrue();

        }
    }
}
